package com.jinmdz.fmis.mapper.mapper.provider;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;
import com.jinmdz.fmis.mapper.entity.MournSessionNumberEntity;

/**
 * 告别厅场次维护表Provider
 * 
 * @author generator
 * @date 2020-08-23 18:11
 */
public class MournSessionNumberProvider {

    /**
     * 增加MournSessionNumber
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String insertMournSessionNumber(@Param("entity") MournSessionNumberEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" mourn_session_number ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" hall_type_code ", " #{entity.hallTypeCode,jdbcType=SMALLINT} ");
                VALUES(" hall_id ", " #{entity.hallId,jdbcType=INTEGER} ");
                VALUES(" session_number ", " #{entity.sessionNumber,jdbcType=SMALLINT} ");
                VALUES(" time_segment ", " #{entity.timeSegment,jdbcType=VARCHAR} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改MournSessionNumber
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String updateMournSessionNumber(@Param("entity") MournSessionNumberEntity entity) {
        return new SQL() {
            {
                UPDATE(" mourn_session_number ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" hall_type_code = #{entity.hallTypeCode,jdbcType=SMALLINT} ");
                SET(" hall_id = #{entity.hallId,jdbcType=INTEGER} ");
                SET(" session_number = #{entity.sessionNumber,jdbcType=SMALLINT} ");
                SET(" time_segment = #{entity.timeSegment,jdbcType=VARCHAR} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询MournSessionNumber列表
     * 
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-08-23 18:11
     */
    public String listMournSessionNumber(@Param("entity") MournSessionNumberEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,hall_type_code,hall_id,session_number,time_segment,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" mourn_session_number ");

                if (entity.getHallTypeCode() != null) {
                    WHERE(" hall_type_code = #{entity.hallTypeCode,jdbcType=SMALLINT} ");
                }

                if (entity.getHallId() != null) {
                    WHERE(" hall_id = #{entity.hallId,jdbcType=INTEGER} ");
                }

                if (entity.getSessionNumber() != null) {
                    WHERE(" session_number = #{entity.sessionNumber,jdbcType=SMALLINT} ");
                }

                if (entity.getTimeSegment() != null) {
                    WHERE(" time_segment = #{entity.timeSegment,jdbcType=VARCHAR} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}